package com.wangdao.wechatmall.controller.wx;

import com.wangdao.wechatmall.bean.bo.wx.GoodsListBO;
import com.wangdao.wechatmall.bean.vo.admin.BaseRespVo;
import com.wangdao.wechatmall.bean.vo.wx.*;
import com.wangdao.wechatmall.service.wx.WXGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @Author: JK
 * @Date: create in 2021/7/11 20:00
 */
@RestController
@RequestMapping("wx/goods")
public class WXGoodsController {
    @Autowired
    WXGoodsService wxGoodsService;

    /**
     * 查询商品总数
     * @return
     */
    @RequestMapping("count")
    public BaseRespVo count() {
        long number = wxGoodsService.queryGoodsNumber();
        return BaseRespVo.ok(new GoodsCountVO(number));
    }

    /**
     * 查询商品类目
     * @param id
     * @return
     */
    @RequestMapping("category")
    public BaseRespVo category(Integer id) {
        GoodsCategoryVO goodsCategoryVO = wxGoodsService.queryCategory(id);
        return BaseRespVo.ok(goodsCategoryVO);
    }

    /**
     * 查询某一类目下的商品列表
     * @param goodsListBO
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(GoodsListBO goodsListBO) {
        GoodsListVO goodsListVO = wxGoodsService.queryGoodsList(goodsListBO);
        return BaseRespVo.ok(goodsListVO);
    }

    /**
     * 查询商品详情
     * @param id
     * @return
     */
    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        WXGoodsDetailVO wxGoodsDetailVO = wxGoodsService.queryGoodsDetail(id);
        return BaseRespVo.ok(wxGoodsDetailVO);
    }

    /**
     * 查询和当前商品详关联的
     * @param id
     * @return
     */
    @RequestMapping("related")
    public BaseRespVo related(Integer id) {
        List<GoodsRelatedVO> goodsRelatedVOS = wxGoodsService.queryGoodsRelated(id);
        return BaseRespVo.ok(goodsRelatedVOS);
    }
}
